﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogicServer;
using Model;

namespace BugSysSolution
{
    public partial class BugReplys : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind(1);
            }
        }

        public void Bind(int index)
        {
            String id = Request["bugid"] ?? String.Empty;
            ReplyLogic rl = new ReplyLogic();
            this.Pager.AlwaysShow = true;
            this.Pager.RecordCount = rl.GetReplyCountByBugId(Convert.ToInt32(id));
            this.rep.DataSource = rl.GetReplyListByBugId(this.Pager.PageSize, index, Convert.ToInt32(id));
            this.rep.DataBind();
        }

        protected void Pager_PageChanged(object sender, EventArgs e)
        {
            Bind(this.Pager.CurrentPageIndex);
        }

        protected void btn_submit_Click(object sender, EventArgs e)
        {
            Users us = Session["user"] as Users;
            String bugid = HFBUGID.Value;
            String content = replycontent.InnerHtml;
            int replyuser = us.Id;
            String replydate = DateTime.Now.ToShortDateString();

            Model.Replys rp = new Model.Replys();
            rp.BugId = Convert.ToInt32(bugid);
            rp.ReplyDate = Convert.ToDateTime(replydate);
            rp.ReplyUser = replyuser;
            rp.ReplyContent = content;

            ReplyLogic rl = new ReplyLogic();
            bool bl = rl.InsertReplys(rp);
            if (bl)
            {
                Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "update", "alert('评论成功!');window.location.href=window.location.href;", true);
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "update", "alert('评论失败!');", true);
            }
        }
    }
}